<? require("core/base.php"); ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>uptime - general stats</title>
<link href="files/main.css" rel="stylesheet" type="text/css">
</head>

<body>
<table width="800" border="0" cellspacing="0" cellpadding="0">
  <tr> 
    <td><a href="index.php"><img src="img/hdr.png" alt="uptime" width="800" height="100" hspace="0" vspace="0" border="0"></a></td>
  </tr>  
  <tr>  
    <td valign="top" class="fons33"><?optionBar();?></td>
  </tr>
  <tr>  
    <td valign="top" class="fons33b">
      <table width="100%" border="0" cellspacing="0" cellpadding="8">
        <tr>
          <td><p><br>
              <span class="destacat"><br>
              <br>
              General stats</span></p>
            <p></a><br>
            </p>
            <table width="780" border="0" cellspacing="1" cellpadding="1">
              <tr> 
                <td width="272" class="hdrtaula">Description</td>
                <td width="501" class="hdrtaula">Value</td>
              </tr>
              <?
	$bd=new bd;
	
	// number of users
	echo("<TR>");
	echo("<TD class=\"celltaulafirst\">Number of users</TD>");
	$sQuery="SELECT COUNT(*) AS res FROM users";
	$bd->query($sQuery);
	$r=$bd->getResultatObj();
	$nu=$r[0]->res;
	
	$sQuery="SELECT COUNT(*) AS res FROM users WHERE admin='t'";
	$bd->query($sQuery);
	$s=$bd->getResultatObj();
	
	if ($s[0]->res==1)
		$t="one of which has got admin privileges";
	else
		$t=$s[0]->res." of which have got admin privileges";
	
	echo("<TD class=\"celltaula\">".$r[0]->res.", ".$t."</TD>");
	echo("</TR>");

	// number of machines
	echo("<TR>");
	echo("<TD class=\"celltaulafirst\">Number of machines</TD>");
	$sQuery="SELECT COUNT(*) AS res FROM machines";
	$bd->query($sQuery);
	$r=$bd->getResultatObj();
	$nm=$r[0]->res;
	echo("<TD class=\"celltaula\">".$r[0]->res."</TD>");
	echo("</TR>");

	// avg machines per user
	echo("<TR>");
	echo("<TD class=\"celltaulafirst\">Average machines per user</TD>");
	echo("<TD class=\"celltaula\">".round($nm/$nu, 1)."</TD>");
	echo("</TR>");

	// avg uptime
	echo("<TR>");
	echo("<TD class=\"celltaulafirst\">Average uptime</TD>");
	$sQuery="SELECT AVG(uptime) AS res FROM uptime";
	$bd->query($sQuery);
	$r=$bd->getResultatObj();
	echo("<TD class=\"celltaula\">".niceUptime(round($r[0]->res))."</TD>");
	echo("</TR>");


	// total uptime
	echo("<TR>");
	echo("<TD class=\"celltaulafirst\">Accumulated uptime</TD>");
	$sQuery="SELECT SUM(uptime) AS res FROM uptime";
	$bd->query($sQuery);
	$r=$bd->getResultatObj();
	echo("<TD class=\"celltaula\">".niceUptime(round($r[0]->res))."</TD>");
	echo("</TR>");
	
	
	// number of OS
	echo("<TR>");
	echo("<TD class=\"celltaulafirst\">Total number of OS</TD>");
	$sQuery="SELECT COUNT(*) AS res FROM os";
	$bd->query($sQuery);
	$r=$bd->getResultatObj();
	echo("<TD class=\"celltaula\">".$r[0]->res."</TD>");
	echo("</TR>");


	// number of CPUs
	echo("<TR>");
	echo("<TD class=\"celltaulafirst\">Total number of CPUs</TD>");
	$sQuery="SELECT COUNT(*) AS res FROM cpus";
	$bd->query($sQuery);
	$r=$bd->getResultatObj();
	echo("<TD class=\"celltaula\">".$r[0]->res."</TD>");
	echo("</TR>");


	// most popular CPUs
	echo("<TR>");
	echo("<TD class=\"celltaulafirst\">Most popular CPUs</TD>");
	$sQuery="SELECT c.cpu, COUNT(*) AS m from configurations c WHERE fin_date IS NULL GROUP BY c.cpu ORDER BY m DESC";
	$bd->query($sQuery);
	$r=$bd->getResultatObj();
	echo("<TD class=\"celltaula\">");
	$ant=-1;
	foreach ($r as $k => $v)
	{
		if ($v->m<$ant)
			break;
			
		echo("-<I>".webstr($v->cpu)."</I>, with ");
		if ($v->m==1)
			echo("one machine<BR>");
		else
			echo($v->m." machines<BR>");
		
		$ant=$v->m;
	}	
	echo("</TD>");
	echo("</TR>");


	// most popular OS
	echo("<TR>");
	echo("<TD class=\"celltaulafirst\">Most popular OS</TD>");
	$sQuery="SELECT s.os, COUNT(*) AS m from configurations c, subversions s WHERE fin_date IS NULL AND s.subversion=c.subversion GROUP BY s.os ORDER BY m DESC";
	$bd->query($sQuery);
	$r=$bd->getResultatObj();
	echo("<TD class=\"celltaula\">");
	$ant=-1;
	foreach ($r as $k => $v)
	{
		if ($v->m<$ant)
			break;
			
		echo("-<I>".webstr($v->os)."</I>, with ");
		if ($v->m==1)
			echo("one machine<BR>");
		else
			echo($v->m." machines<BR>");
		
		$ant=$v->m;
	}	
	echo("</TD>");
	echo("</TR>");



	// user with most machines
	echo("<TR>");
	echo("<TD class=\"celltaulafirst\">User with most machines</TD>");
	$sQuery=" SELECT username, COUNT(*) AS res FROM machines GROUP BY username ORDER BY res DESC";
	$bd->query($sQuery);
	$r=$bd->getResultatObj();
	
	if ($r[0]->res==1)
		$t="one machine";
	else
		$t=$r[0]->res." machines";
	echo("<TD class=\"celltaula\">".$r[0]->username.", with ".$t."</TD>");
	echo("</TR>");


	// user with least machines
	echo("<TR>");
	echo("<TD class=\"celltaulafirst\">User with least machines</TD>");
	$sQuery=" SELECT username, COUNT(*) AS res FROM machines GROUP BY username ORDER BY res";
	$bd->query($sQuery);
	$r=$bd->getResultatObj();
	
	if ($r[0]->res==1)
		$t="one machine";
	else
		$t=$r[0]->res." machines";
	echo("<TD class=\"celltaula\">".$r[0]->username.", with ".$t."</TD>");
	echo("</TR>");
	

?>
            </table>
            <p><br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
            </p>
	<DIV align="right">
      <a href="http://validator.w3.org/check?uri=referer"><img border="0"
          src="http://www.w3.org/Icons/valid-html401"
          alt="Valid HTML 4.01!" height="31" width="88"></a>
    </DIV>			
            <p>&nbsp;</p></td>
        </tr>
      </table>
      
    </td>
  </tr>
</table>
</body>
</html>
